# Contributor: Laurent Bercot <ska-devel@skarnet.org>
# Maintainer: Laurent Bercot <ska-devel@skarnet.org>
pkgname=tipidee
pkgver=0.0.5.1
pkgrel=0
pkgdesc="The skarnet.org web server"
url=https://skarnet.org/software/tipidee/
arch="all"
options="!check"  # No test suite.
license="ISC"
_skalibs_version=2.14.3
depends="execline s6 s6-networking"
makedepends="skalibs-dev>=${_skalibs_version}"
subpackages="$pkgname-static $pkgname-libs $pkgname-dev $pkgname-doc $pkgname-openrc"
source="
	https://skarnet.org/software/tipidee/tipidee-$pkgver.tar.gz
	httpd.run
	httpsd.run
	logger.run
	tipidee.conf
	tipidee.confd
	tipidee.initd
	tipidee.pc.in
	"
install="
	tipidee.pre-install
	tipidee.post-install
	tipidee.post-deinstall
	"
pkggroups="tipidee"
pkgusers="tipideelog tipideed"

build() {
	./configure \
		--enable-shared \
		--disable-allstatic \
		--prefix=/usr \
		--sysconfdir=/etc \
		--libexecdir="/usr/lib/$pkgname"
	make
}

_makeservicedir() {
	name="http${1}d-${2}"
	fn="$pkgdir/var/lib/tipidee/services/$name"
	logdir="$pkgdir/var/log/$name"
	mkdir -p "$fn/log" "$logdir"
	chown tipideelog:tipidee "$logdir"
	chmod 02755 "$logdir"
	echo 3 > "$fn/log/notification-fd"
	sed -e "s/@S@/${1}/g; s/@V@/${2}/g;" "$srcdir/logger.run" > "$fn/log/run"
	chmod 0755 "$fn/log/run"
	echo 3 > "$fn/notification-fd"
	sed -e "s/@V@/${2}/g;" "$srcdir/http${1}d.run" > "$fn/run"
	chmod 0755 "$fn/run"
}

package() {
	mkdir -p "$pkgdir/usr/share/doc" "$pkgdir/var/lib/tipidee/docroot"
	make DESTDIR="$pkgdir" install
	for i in '' s ; do for j in 4 6 ; do
		_makeservicedir "$i" "$j"
	done ; done
	install -D -m 0644 "$srcdir/tipidee.conf" "$pkgdir/etc/tipidee.conf"
	install -D -m 0644 "$srcdir/tipidee.confd" "$pkgdir/etc/conf.d/tipidee"
	install -D -m 0755 "$srcdir/tipidee.initd" "$pkgdir/etc/init.d/tipidee"
	sed -e "s/@@VERSION@@/$pkgver/g; s/@@SKALIBS_VERSION@@/${_skalibs_version}/g;" "$srcdir/$pkgname.pc.in" > "$srcdir/$pkgname.pc"
	install -D -m 0644 "$srcdir/$pkgname.pc" "$pkgdir/usr/lib/pkgconfig/$pkgname.pc"
	cp -a "$builddir/doc" "$pkgdir/usr/share/doc/$pkgname"
}

dev() {
	default_dev

	# default_dev please stop being stupid
	mv "$subpkgdir/usr/bin/tipidee-config" "$pkgdir/usr/bin/tipidee-config"
}

sha512sums="
2f0ae2b3f7c7782785e8498e482bb4cfbb58c0bbe1689b2d3a5a4970783704147e8e5b96737970e2a542ee409e2b179a199a990fbf20b3ea4083cd47d16960cf  tipidee-0.0.5.1.tar.gz
2793470ce7b1ad35e0716fc9e654b010aea7e78d0997a6829057a610790f11b9e36bbe94efda87fbae19a5cae16c207558299fb2a11ebebb55fceb235db09b83  httpd.run
9b74cd76ca681a8b2692d691379a4648672339cca72c83ec7a62a8f62f13640893822029850677454b6f18c3cf5cb2316d84c62e2acd8e86a1c678167f4f974f  httpsd.run
f2e855c08948681ccf13fced61c58aab4c1a256f7c2e94922eeb27948fd7b95cbf57126aeb94e491cc67503e0d2b6d8cc83c7e6fa9de90621c04098283a2ebf8  logger.run
bb2681a3000133724bb8fd4918bc3209ea676c2e4f96ad8b298d8e7302aeebd6876341ea205f2d808f34e4c9b5c138bba032694c6069c17026b0ddf23702f9ba  tipidee.conf
7a999200ad21b2b0737ce82136bc8e055d7ab4a865b7727e6dc8df0eaeea6ace11eb5756b64231ce7938d11b5ec218944173ea1df3db059d033bf3f848c9a608  tipidee.confd
9e0c8ed97894c60dc37b38debf9e087228c259e08bb6a17b35c756bcaa57903d3608620eb26aba6295c0fb087e4ab4c551bc65acd37d8b92b7b9e1c911542dd1  tipidee.initd
21e71ed438270598de55631c46006bcb66528889477d1a09c76db4160d46651b1c657b31913393115c01aae4853afa4fe425a6fb3985ea8fa403de1d36e3f2f1  tipidee.pc.in
"
